import Mock from 'mockjs'
import { getAllQuery } from './paramsDeal'
import { validateToken } from './tokenValidate'

const orgList = (options) => {
    // console.log('options', options)
    const params = getAllQuery(options.url)
    const loginTimeStamp = params.timeStamp
    const token = params.token
    const isTokenValid = validateToken(loginTimeStamp, token)
    if (!token) {
        return {
            status: 400,
            message: 'token不能为空',
            data: {}
        }
    }
    // console.log('org===token====isTokenValid', token, isTokenValid)
    if (!isTokenValid && token == 123456) {
        return {
            status: 401,
            message: 'token失效',
            data: {}
        }
    }
    return Mock.mock({
        status: 200,
        message: 'success',
        data: {
            total: 10,
            'rows|10': [
                {
                    id: '@guid',
                    'orgName|1': ['采购部门', '采购子部门', '采购子子部门', '采购子子子部门'],
                    'orgCode|1': ['100000', '100001', '100002', '100003']
                }
            ]
        }
    })
}

export default {
    'get|/api/testStudy/service/orgList': (options) => orgList(options)
}
